using System;
using System.Collections.Generic;

namespace SCADAEditor.Component
{
    public class ComponentList
    {
        private readonly Dictionary<ComponentType, ComponentBase> _prototypes = new Dictionary<ComponentType, ComponentBase>();

        public void RegisterComponent(ComponentType type, ComponentBase prototype)
        {
            _prototypes[type] = prototype;
        }

        public ComponentBase CreateComponent(ComponentType type)
        {
            if (_prototypes.TryGetValue(type, out var prototype))
            {
                return prototype.Clone();
            }
            return null;
        }

        public IEnumerable<ComponentType> GetAvailableComponents()
        {
            return _prototypes.Keys;
        }

        public ComponentType GetComponentType(ComponentBase component)
        {
            if (component is ButtonComponent) return ComponentType.功能键;
            if (component is TextAnnotationComponent) return ComponentType.文字批注;
            if (component is DateTimeComponent) return ComponentType.日期时间;
            if (component is StatusIndicatorComponent) return ComponentType.位状态指示灯;
            throw new NotSupportedException($"不支持的组件类型: {component.GetType().Name}");
        }

    }
}